package cn.fz.learn02.controller.socket;

import cn.hutool.core.date.DateTime;
import cn.hutool.http.HttpStatus;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("socket")
public class SocketOpsController {
    @Resource
    private WebSocketServer webSocketServer;

    @GetMapping("publish")
    public String publish(String message, String userId){
        Map<String,Object> result = new HashMap<>();
        result.put("code", HttpStatus.HTTP_OK);
        result.put("message",message);
        result.put("date", DateTime.now().toString());
        JSONObject obj = new JSONObject(result);
        // webSocketServer.sendOneMessage(userId, obj.toJSONString());
        return "success";
    }
}
